﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AuthorityPage.aspx.cs"
    Inherits="Saker.Web.Boss.Sys.Modules.AuthorityPage" %>

<%@ Register Src="../../../Controls/Pager.ascx" TagName="Pager" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../../Styles/global.css?v=1.0" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/jBox/Skins/Green/jbox.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/jquery.utils.js" type="text/javascript"></script>
    <script src="../../../Scripts/admin.js?v=1.0" type="text/javascript"></script>
    <script src="../../../Scripts/admin.ui.js?v=1.0" type="text/javascript"></script>
    <script src="../../../Scripts/jBox/jquery.jBox-2.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        admin.config.indexUrl = '/Boss/Main.aspx';
        var loading_img = "../../../images/loading_16x16.gif";

        // 只调用最顶的jBox
        if (top.jBox != undefined) {
            window.jBox = top.jBox;
        }

        top.orderChanged = false;
        function checkReload() {
            if (top.orderChanged) {
                top.orderChanged = false;
                goUrl(location.href);
            }
        }

        function checkAll(chk, id) {
            if (id == undefined)
                $("input[type='checkbox']").each(function () { this.checked = chk.checked; });
            else {
                $("#" + id + " input[type='checkbox']").each(function () { this.checked = chk.checked; });
            }
        }

        function goUrl(url) {
            top.admin.ui.goUrl(url);
            // 可能在jBox里点击跳转，同时关闭它
            jBox.close();
        }
        function doAddAuthority() {
            var html =
                ' <table class="data-form" cellspacing="0" cellpadding="0">' +
            '<tbody>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限名称：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="name" name="name" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限标签：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="tag" name="tag" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限说明：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="des" name="des" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限排序：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="order" name="order" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
            '</tbody>' +
        '</table>';
            var submit = function (v, h, f) {
                if (f.name == '') {
                    jBox.tip("请输入权限名称。", 'error', { focusId: "name" });
                    return false;
                }
                // 提交数据
                jBox.tip('正在处理...', 'loading');
                $.postJson('AuthorityAdd.ashx?CMD=add', { name: f.name, tag: f.tag, des: f.des, order: f.order }, function (data) {
                    if (data.code != 1) {
                        jBox.tip(data.message, 'error');
                    }
                    else {
                        jBox.close();
                        jBox.tip(data.message, 'success');
                        window.location.href = "AuthorityPage.aspx";
                    }
                }, function () {
                    jBox.tip("服务器出错！", 'error');
                });

                return false;
            };
            jBox.open(html, "添加权限", 500, 'auto', { submit: submit });
        }
        function doEditAuthority(id) {
            var html = "";
            jQuery.ajax({
                url: 'AuthorityAdd.ashx',
                cache: true,
                type: 'post',
                data: "CMD=get&id=" + id,
                dataType: "json",
                success: function (result, textStatus) {
                    if (result != null) {
                        html = ' <table class="data-form" cellspacing="0" cellpadding="0">' +
            '<tbody>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限名称：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="name" value="'+result.AuthorityName+'" name="name" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限标签：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="tag" value="' + result.AuthorityTag + '" name="tag" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限说明：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="des" value="' + result.AuthorityDescription + '" name="des" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
                '<tr>' +
                    '<th scope="row">' +
                        '权限排序：' +
                    '</th>' +
                    '<td>' +
                        '<input type="text" id="order" value="' + result.AuthorityOrder + '" name="order" class="input-normal" />' +
                    '</td>' +
                '</tr>' +
            '</tbody>' +
        '</table>';
                        var submit = function (v, h, f) {
                            if (v == 'ok') {
                                if (f.name == '') {
                                    jBox.tip("请输入权限名称。", 'error', { focusId: "name" });
                                    return false;
                                }
                                jBox.tip('正在处理...', 'loading');
                                $.postJson('AuthorityAdd.ashx?CMD=edit', { id: id, name: f.name, tag: f.tag, des: f.des, order: f.order }, function (data) {
                                    if (data.code != 1) {
                                        jBox.tip(data.message, 'error');
                                    }
                                    else {
                                        jBox.close();
                                        jBox.tip(data.message, 'success');
                                        window.location.href = "AuthorityPage.aspx";
                                    }
                                }, function () {
                                    jBox.tip("服务器出错！", 'error');
                                });
                            }
                            return false;
                        };
                        jBox.open(html, "编辑权限", 500, 'auto', { submit: submit });
                    }
                    else {
                    }
                },
                complete: function () {
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="block-wp">
        <div class="block-sep">
        </div>
        <div class="block">
            <div class="h">
                <span class="icon-sprite icon-list"></span>
                <h3>
                    权限列表</h3>
                <div class="bar">
                    <a class="btn-lit" href="javascript:doAddAuthority();"><span>新增</span></a>
                </div>
            </div>
            <div class="tl corner">
            </div>
            <div class="tr corner">
            </div>
            <div class="bl corner">
            </div>
            <div class="br corner">
            </div>
            <div class="cnt-wp">
                <div class="cnt">
                    <table class="data-table" width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <th scope="col">
                                    权限名
                                </th>
                                <th scope="col">
                                    标签
                                </th>
                                <th scope="col">
                                    描述
                                </th>
                                <th scope="col">
                                    排序
                                </th>
                                <th scope="col">
                                    编辑
                                </th>
                                <th scope="col">
                                    删除
                                </th>
                            </tr>
                            <asp:Repeater ID="AuthorityList" runat="server" OnItemCommand="AuthorityList_ItemCommand">
                                <ItemTemplate>
                                    <tr>
                                        <td class="txt80 c">
                                            <%#Eval("AuthorityName")%>
                                        </td>
                                        <td class="txt80 c">
                                            <%#Eval("AuthorityTag")%>
                                        </td>
                                        <td class="txt160 c">
                                            <%#Eval("AuthorityDescription")%>
                                        </td>
                                        <td class="txt80 c">
                                            <%#Eval("AuthorityOrder")%>
                                        </td>
                                        <td class="icon">
                                            <a class="opt" onclick="JavaScript:doEditAuthority(<%#Eval("AuthorityID")%>)"><span
                                                class="icon-sprite icon-edit"></span></a>
                                        </td>
                                        <td class="icon tail">
                                            <asp:LinkButton CssClass="opt" ID="lbtnDel" CommandArgument='<%#Eval("AuthorityID")%>'
                                                CommandName="DeleteAuthority" runat="server" OnClientClick="JavaScript:return confirm('你确定要删除该用户吗？');"><span class="icon-sprite icon-delete"></span></asp:LinkButton>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                    </table>
                </div>
                <uc1:Pager ID="AuthorityPager" runat="server" OnPageChanged="BindData" PageSize="12" />
            </div>
        </div>
    </div>
    <!--#wp-->
    </form>
</body>
</html>
